package com.oa.srms.apps.actions.goods;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;

import com.oa.srms.apps.actions.BasicAction;
import com.oa.srms.apps.business.goods.IGoodCategoryService;
import com.oa.srms.apps.entity.goods.GoodCategoryValue;

@SuppressWarnings("serial")
public class GoodCategoryAction extends BasicAction {
	
	@Autowired
	private IGoodCategoryService goodCategoryService;

	private String categoryNo;
	private String categoryName;
	private String categoryId;
	private String categoryIds;

	private List<GoodCategoryValue> goodCategoryList;

	public String toQuery() throws Exception {
		goodCategoryList = goodCategoryService.quaryGoodCategoryValue(null);
		count = goodCategoryList.size();
		return "toQueryPage";
	}
	
	public String add() throws Exception {
		goodCategoryService.addGoodCategory(categoryNo, categoryName);
		return "toQuery";
	}
	
	public String delete() throws Exception {
		if(categoryId != null)
			goodCategoryService.deleteGoodCategory(Integer.parseInt(categoryId));
		if(categoryIds != null){
			String[] categoryArr = categoryIds.split(",");
			for(String categoryItem : categoryArr){
				goodCategoryService.deleteGoodCategory(Integer.parseInt(categoryItem));
			}
		}
		return "toQuery";
	}
	
	public String modify() throws Exception{
		goodCategoryService.modifyGoodCategory(Integer.parseInt(categoryId), categoryNo, categoryName);
		return null;
	}
	
	public String toEnable() throws Exception {
		goodCategoryService.toEnable(Integer.parseInt(categoryId));
		return "toQuery";
	}
	
	public String toDisable() throws Exception {
		goodCategoryService.toDisable(Integer.parseInt(categoryId));
		return "toQuery";
	}

	// Getter and Setter
	public String getCategoryNo() {
		return categoryNo;
	}

	public void setCategoryNo(String categoryNo) {
		this.categoryNo = categoryNo;
	}

	public String getCategoryName() {
		return categoryName;
	}

	public void setCategoryName(String categoryName) {
		this.categoryName = categoryName;
	}

	public List<GoodCategoryValue> getGoodCategoryList() {
		return goodCategoryList;
	}

	public void setGoodCategoryList(List<GoodCategoryValue> goodCategoryList) {
		this.goodCategoryList = goodCategoryList;
	}

	public String getCategoryId() {
		return categoryId;
	}

	public void setCategoryId(String categoryId) {
		this.categoryId = categoryId;
	}

	public String getCategoryIds() {
		return categoryIds;
	}

	public void setCategoryIds(String categoryIds) {
		this.categoryIds = categoryIds;
	}

}
